-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[resources] Add functions to retrieve bytes from drawable or font resources. #4651
Conversation
...ts/resources/library/src/commonMain/kotlin/org/jetbrains/compose/resources/ImageResources.kt
Outdated
Show resolved
Hide resolved
...ts/resources/library/src/commonMain/kotlin/org/jetbrains/compose/resources/ImageResources.kt
Outdated
Show resolved
Hide resolved
...ts/resources/library/src/commonMain/kotlin/org/jetbrains/compose/resources/ImageResources.kt
Outdated
Show resolved
Hide resolved
47bd458
to
4c1bb1e
Compare
…e loading functions and function to get current compose environment
4c1bb1e
to
cd26460
Compare
...sources/library/src/commonMain/kotlin/org/jetbrains/compose/resources/ResourceEnvironment.kt
Outdated
Show resolved
Hide resolved
...nts/resources/library/src/commonMain/kotlin/org/jetbrains/compose/resources/FontResources.kt
Outdated
Show resolved
Hide resolved
@ExperimentalResourceApi | ||
suspend fun getFontResourceBytes( | ||
environment: ResourceEnvironment = getResourceEnvironment(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having environment
on the first place forces users to use resource
name explicitly. Was this the intention?
I don't have a strong opinion here. On one hand, it is better for users to make a conscience choice to use the system environment, on the other hand it is verbose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it was done to avoid parameters after a vararg in
suspend fun getString(
environment: ResourceEnvironment,
resource: StringResource,
vararg formatArgs: Any
): String
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, I would suggest to do the same for the other functions - split them into 2:
@ExperimentalResourceApi
suspend fun getFontResourceBytes(
environment: ResourceEnvironment,
resource: FontResource
): ByteArray
@ExperimentalResourceApi
suspend fun getFontResourceBytes(
environment: ResourceEnvironment,
): ByteArray = getFontResourceBytes(getSystemResourceEnvironment(), resource)
Otherwise we can't write getDrawableResourceBytes(Res.drawable.title)
, only getDrawableResourceBytes(resource = Res.drawable.title)
...nts/resources/library/src/commonMain/kotlin/org/jetbrains/compose/resources/FontResources.kt
Show resolved
Hide resolved
...ources/library/src/commonMain/kotlin/org/jetbrains/compose/resources/StringArrayResources.kt
Show resolved
Hide resolved
Because resources are not supported on native message targets.
...urces/library/src/commonMain/kotlin/org/jetbrains/compose/resources/PluralStringResources.kt
Show resolved
Hide resolved
...urces/library/src/commonMain/kotlin/org/jetbrains/compose/resources/PluralStringResources.kt
Show resolved
Hide resolved
val theme: ThemeQualifier, | ||
val density: DensityQualifier | ||
@ExperimentalResourceApi | ||
data class ResourceEnvironment internal constructor( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented two new experimental functions:
fixes #4360